# 实现列表的减法操作
class MyList(list):
    def __sub__(self, other):
        new_list=[]
        for i in self:
            if i not in other:
                new_list.append(i)
        return new_list

# 实现数字的乘法
class Mul:
    def __init__(self,value):
        self.value=value
    def __mul__(self, other):
        return self.value*other.value

class HomWork:
    def __init__(self,title,money,data):
        self.title=title
        self.money=money
        self.data=data
    def __setattr__(self, key, value):
        if key=="title":
            if isinstance(value,str):
                super().__setattr__(key,value)
            else:
                raise TypeError("title只能是字符串类型")
        elif key=="money":
            if isinstance(value,int):
                if value>0:
                    super().__setattr__(key,value)
                if value<=0:
                    super().__setattr__(key, 0)
            else:
                raise TypeError("money只能是int类型")
        elif key=="data":
            super().__setattr__(key,value)
        else:
            raise TypeError("只能设置title，money，data这三个属性，不持支其他属性")

    def __delattr__(self, item):
        if item=="data":
            raise TypeError("data属性不能被删除")
        else:
            super().__delattr__(self,item)

# 作业1
a=MyList([11,22,33,44])
b=MyList([11,33])
print(a-b)

m=Mul(3)
n=Mul(4)
print(m*n)

# 作业2
hm=HomWork("3",1,1)
print(hm.title,hm.money,hm.data)
# del hm.data
# setattr(hm,"name2",1) #设置不支持的属性
setattr(hm,"title","zhangsan")
print(hm.title)
